#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>

const int mx = 1e6 + 5;

struct Edg{
    int u, v, w, nxt;
}edg[mx];

int CNT;
int head[mx];

void add_edg(int u, int v, int w = 1){
    edg[++CNT] = (Edg){u, v, w, head[u]};
    head[u] = CNT;
}

int n, m, L, V;
int d[mx], v[mx], a[mx], p[mx];

namespace pts100{
    int ans1, ans2;
    int l[mx], r[mx], pre[mx], prel[mx];

    priority_queue<pii, vector<pii>, greater<pii> > p2;
    priority_queue<int, vector<int>, greater<int> > p1;

    void solve(){
        while(!p1.empty()) p1.pop();
        while(!p2.empty()) p2.pop();
        ans1 = 0, ans2 = 0;
        for(int i = 0; i <= L; i++) prel[i] = pre[i] = 0;
        // cerr << 1;
        for(int i = 1; i <= n; i++){
            l[i] = r[i] = -1;
            if(a[i] == 0){
                if(v[i] > V) l[i] = d[i], r[i] = L;
            }else if(a[i] > 0){
                if(v[i] > V){
                    l[i] = d[i], r[i] = L;
                    continue;
                }
                int x = V * V - v[i] * v[i];
                int y = a[i] * 2;
                // a[i] *= 2;
                l[i] = x / y + 1 + d[i];
                r[i] = L;
            }else{
                if(v[i] <= V) continue;
                int x = v[i] * v[i] - V * V;
                int y = a[i] * -2;
                // a[i] *= -2;
                l[i] = d[i];
                r[i] = d[i] + x / y - (x % y ? 0 : 1);
            }
            // r[i] = max(r[i], 0ll);
            r[i] = min(r[i], L);
            
            if(l[i] > L || l[i] > r[i] || l[i] == -1 || r[i] == -1) continue;
            int vl = v[i] * v[i] + 2 * a[i] * (l[i] - d[i]);
            if(V * V >= vl) cerr << 1;
            int vr = v[i] * v[i] + 2 * a[i] * (r[i] - d[i]);
            if(V * V >= vr) cerr << 2;
            // l[i] = max(l[i], 0ll);
            // l[i] = min(l[i], L);
            // cerr << l[i] << ' ' << r[i] << '\n';
        }
        // cerr << 2;
        for(int i = 1; i <= m; i++){
            pre[p[i]] = i;
        }
        // pre[p[m] + 1] = m + 1;
        for(int i = 1; i <= L; i++){
            if(!pre[i]) pre[i] = pre[i - 1];
            // prel[i] = pre[i - 1];
        }
        // cerr << '\n';
        for(int i = 1; i <= n; i++){
            // cerr << 'a';
            if(l[i] > L || l[i] > r[i] || l[i] > p[m] || r[i] < p[1] || l[i] == -1 || r[i] == -1) continue;
            // l[i] = prel[i] + 1;
            if(l[i]) l[i] = pre[l[i] - 1] + 1;
            else l[i] = pre[l[i]];
            // cerr << 'b';
            r[i] = pre[r[i]];
            // cerr << 'c';
            // cerr << l[i] << ' ' << r[i] << '\n';
            if(l[i] <= r[i] && r[i]) p2.push({l[i], r[i]}), ans1++;
        }
        // cerr << 3;
        // cerr << '\n';
        while(!p2.empty()){
            pii x = p2.top(); p2.pop();
            if(p1.size()){
                if(p1.top() < x.first){
                    ans2++;
                    while(!p1.empty()) p1.pop();
                }
            }
            p1.push(x.second);
            while(!p2.empty()){
                if(p2.top().first != x.first) break;
                p1.push(p2.top().second); p2.pop();
            }
            if(p1.size()){
                if(p1.top() == x.first){
                    ans2++;
                    while(!p1.empty()) p1.pop();
                }
            }
        }
        if(p1.size()) ans2++;
        cout << ans1 << ' ' << m - ans2 << '\n';
        // cerr << 4;
    }
}

void solve(){
    cin >> n >> m >> L >> V;
    for(int i = 1; i <= n; i++) cin >> d[i] >> v[i] >> a[i];
    for(int i = 1; i <= m; i++) cin >> p[i];
    pts100::solve();
}

signed main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1; cin >> T;
    // T = 1;
    while(T--) solve();
}